import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		currentType: '',
		typesList: [
			{name: '日常检查', form: [
				{name: '检查人', prop: 'dailyCheck.chencUser', type: 'input', value: ''},
				{name: '混凝土建筑物', prop: 'dailyCheck.concrete', type: 'input', value: '正常'},
				{name: '土方建筑物', prop: 'dailyCheck.earthwork', type: 'input', value: '正常'},
				{name: '机电设备', prop: 'dailyCheck.mechanical', type: 'input', value: '正常'},
				{name: '工程完整性', prop: 'dailyCheck.projectInfo', type: 'input', value: '正常'},
				{name: '石方建筑物', prop: 'dailyCheck.rocky', type: 'input', value: '正常'},
				{name: '启闭机和闸门', prop: 'dailyCheck.sluiceGate', type: 'input', value: '正常'},
				{name: '上下游漂浮物和水流', prop: 'dailyCheck.waterObstacle', type: 'input', value: '正常'},
			], type: 1, needQrcode: true, api: '/manage/anony/app/save-daily_check', extraData: {user: ''}},
			{name: '设备巡查', form: [
				{name: '工程名称', prop: 'projectName', type: 'input', value: ''},
				{name: '图片', prop: 'fileUrl', type: 'upload', value: []},
				{name: '巡查描述', prop: 'remark', type: 'input', value: '正常'},
				{name: '状态', prop: 'status', type: 'input', value: '正常'},
				{name: '水位', prop: 'water', type: 'input', value: '正常'},
				{name: '天气', prop: 'weather', type: 'input', value: '正常'},
			], type: 1, needQrcode: false, api: '/manage/anony/app/save-device_trail', extraData: {user: ''}},
			{name: '汛前检查', form: [], type: 2, needQrcode: true, api: '/manage/anony/app/other_check', extraData: {type: 1, chencUser: ''}},
			{name: '特别检查', form: [], type: 2, needQrcode: true, api: '/manage/anony/app/other_check', extraData: {type: 2, chencUser: ''}},
			{name: '年度检查', form: [], type: 2, needQrcode: true, api: '/manage/anony/app/other_check', extraData: {type: 3, chencUser: ''}},
		],
		commonForm: [
			{name: '土建工程', form: [
				{name: '岸墙', prop: 'civilProject.bankWall', type: 'input', value: '正常'},
				{name: '堤防', prop: 'civilProject.levees', type: 'input', value: '正常'},
				{name: '河床', prop: 'civilProject.riverbed', type: 'input', value: '正常'},
				{name: '闸墩及拱圈', prop: 'civilProject.gatePier', type: 'input', value: '正常'},
				{name: '翼墙', prop: 'civilProject.wingWall', type: 'input', value: '正常'},
				{name: '干(浆)砌护底', prop: 'civilProject.slurry', type: 'input', value: '正常'},
				{name: '三桥', prop: 'civilProject.sanqiao', type: 'input', value: '正常'},
				{name: '防渗排水', prop: 'civilProject.drainage', type: 'input', value: '正常'},
				{name: '消能防冲', prop: 'civilProject.antiScour', type: 'input', value: '正常'},
				{name: '启闭机室和管理房', prop: 'civilProject.hoistRoom', type: 'input', value: '正常'},
				{name: '闸室', prop: 'civilProject.lockChamber', type: 'input', value: '正常'},
			], active: true},
			{name: '闸门', form: [
				{name: '面板', prop: 'gate.panel', type: 'input', value: '正常'},
				{name: '梁系', prop: 'gate.beam', type: 'input', value: '正常'},
				{name: '支臂杆', prop: 'gate.outrigger', type: 'input', value: '正常'},
				{name: '吊座', prop: 'gate.hangers', type: 'input', value: '正常'},
				{name: '主、侧滚轮', prop: 'gate.roller', type: 'input', value: '正常'},
				{name: '滑道滑块', prop: 'gate.slideway', type: 'input', value: '正常'},
				{name: '铰链铰座', prop: 'gate.hinge', type: 'input', value: '正常'},
				{name: '门槽', prop: 'gate.groove', type: 'input', value: '正常'},
				{name: '止水座', prop: 'gate.waterstopBottom', type: 'input', value: '正常'},
				{name: '止水', prop: 'gate.waterstop', type: 'input', value: '正常'},
				{name: '压板铁', prop: 'gate.platen', type: 'input', value: '正常'},
				{name: '涂装涂料', prop: 'gate.coating', type: 'input', value: '正常'},
				{name: '金属涂层', prop: 'gate.metallicCoating', type: 'input', value: '正常'},
			], active: false},
			{name: '启闭机', form: [
				{name: '减速器', prop: 'hoist.retarder', type: 'input', value: '正常'},
				{name: '联轴器', prop: 'hoist.coupling', type: 'input', value: '正常'},
				{name: '制动器', prop: 'hoist.brake', type: 'input', value: '正常'},
				{name: '轴承', prop: 'hoist.bearing', type: 'input', value: '正常'},
				{name: '润滑系统', prop: 'hoist.lubrication', type: 'input', value: '正常'},
				{name: '手摇机构', prop: 'hoist.handShake', type: 'input', value: '正常'},
				{name: '护罩', prop: 'hoist.shield', type: 'input', value: '正常'},
				{name: '油压传动部分', prop: 'hoist.oilPressure', type: 'input', value: '正常'},
				{name: '螺杆', prop: 'hoist.screw', type: 'input', value: '正常'},
				{name: '吊头', prop: 'hoist.hangingHead', type: 'input', value: '正常'},
			], active: false},
			{name: '电气设备及自动监控系统', form: [
				{name: '线路', prop: 'electricAccessory.line', type: 'input', value: '正常'},
				{name: '操作保护设备', prop: 'electricAccessory.operateDevice', type: 'input', value: '正常'},
				{name: '电动机', prop: 'electricAccessory.motor', type: 'input', value: '正常'},
				{name: '变压器', prop: 'electricAccessory.transformer', type: 'input', value: '正常'},
				{name: '备用电源', prop: 'electricAccessory.backupPower', type: 'input', value: '正常'},
				{name: '避雷设施', prop: 'electricAccessory.lightningProtection', type: 'input', value: '正常'},
				{name: '照明设备', prop: 'electricAccessory.lighting', type: 'input', value: '正常'},
				{name: '视频监视系统', prop: 'electricAccessory.videoSys', type: 'input', value: '正常'},
				{name: '自动监测系统', prop: 'electricAccessory.autoMonitorSys', type: 'input', value: '正常'},
				{name: '自动控制系统', prop: 'electricAccessory.autoControlSys', type: 'input', value: '正常'},
			], active: false},
			{name: '工程安全设施', form: [
				{name: '测压管', prop: 'projectSafety.pressure', type: 'input', value: '正常'},
				{name: '伸缩缝标点', prop: 'projectSafety.expansionJoint', type: 'input', value: '正常'},
				{name: '水尺', prop: 'projectSafety.waterGauge', type: 'input', value: '正常'},
				{name: '水准基点及位移标点', prop: 'projectSafety.shiftPoint', type: 'input', value: '正常'},
				{name: '道路', prop: 'projectSafety.road', type: 'input', value: '正常'},
				{name: '防汛车辆', prop: 'projectSafety.floodCar', type: 'input', value: '正常'},
				{name: '通讯设施', prop: 'projectSafety.communication', type: 'input', value: '正常'},
				{name: '道路警示标志', prop: 'projectSafety.roadWarning', type: 'input', value: '正常'},
				{name: '消防设施', prop: 'projectSafety.fireControl', type: 'input', value: '正常'},
				{name: '事故检修门', prop: 'projectSafety.overhaulRoon', type: 'input', value: '正常'},
				{name: '防汛工器具', prop: 'projectSafety.floodPreventionTool', type: 'input', value: '正常'},
				{name: '防汛备料', prop: 'projectSafety.floodPreventionMaterial', type: 'input', value: '正常'},
				{name: '违章建筑', prop: 'projectSafety.illegalBuild', type: 'input', value: '正常'},
				{name: '违章活动', prop: 'projectSafety.illegalActivities', type: 'input', value: '正常'},
			], active: false},
			{name: '其他', form: [
				{name: '林木', prop: 'other.forest', type: 'input', value: '正常'},
				{name: '草坪', prop: 'other.lawn', type: 'input', value: '正常'},
				{name: '绿篱花卉', prop: 'other.hedgeFlower', type: 'input', value: '正常'},
				{name: '其他补充', prop: 'other.otherContent', type: 'input', value: '正常'},
			], active: false},
		]
	},
	mutations: {
		setCurrentType(state, data) {
			state.currentType = data
			if (data.type === 1) state.currentType.extraData.user = uni.getStorageSync('name')
			else if (data.type === 2) {
				state.currentType.extraData.chencUser = uni.getStorageSync('name')
				state.currentType.form = state.commonForm.filter(v => v.active)[0].form
			}
		},
		changeCommonFormType(state, k) {
			state.commonForm.forEach((v, i) => {
				v.active = i === k
			})
			state.currentType.form = state.commonForm.filter(v => v.active)[0].form
		},
		resetCurrentValue(state) {
			state.currentType.form.forEach(v => {
				v.value = v.type === 'upload' ? [] : '正常'
				if (['工程名称', '检查人'].indexOf(v.name) > -1) v.value = ''
			})
			state.commonForm.forEach(x => {
				x.form.forEach(y => {
					y.value = '正常'
				})
			})
		}
	}
})

export default store